<?php
/**
 * 地区管理
 */

namespace app\badmin\controller;


use app\common\controller\BadminController;
use app\badmin\model\Region as RegionModel;
use think\Exception;

class Region extends BadminController {

    protected $isArrayResult = ['childregion'];

    /**
     * 房源表需要
     * 省市区联动
     * @return false|string
     */
    public function childRegion() {
        try {
            $params = $this->checkParams('id');
            if ($params === false) return $this->resErr();
            $list = RegionModel::where('pid', $params['id'])
                ->field('id,name,city_code')
                ->order('weights', 'asc')
                ->select();//市或者区
            return $this->resData('success', $list);
        } catch (Exception $e) {
            return $this->resErr($e->getMessage(), $e->getCode());
        }
    }

    /**
     * 在公司拥有的城市当中切换
     * @return false|string
     */
    public function location() {
        try {
            $params = $this->checkParams('');
            if ($params === false) return $this->resErr();
            $list = RegionModel::indexCity($params);
            return $this->resData('success', $list);
        } catch (Exception $e) {
            return $this->resErr($e->getMessage(), $e->getCode());
        }
    }

}